home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
unixt~3h
/
unixtkit.arc
/
man.arc
/
SH.MAN
< prev
next >
Wrap
Text File
|
1988-03-28
|
14KB
|
463 lines
SH ST-UNIX User's Manual SH
COMMAND
sh - comamnd line interpreter
FORMAT
sh [ -enstuvx ] [ file ] ...
DESCRIPTION
_✓S_✓h is a command line interpreter nterface to GEMDOS. It per-
mits the typing of commands from the keyboard and replaces
the GEM desktop.
The shell provides features found in programming languages
such as varaibles and loops.
OPTIONS
-e if the shell is not in interactive mode (ie. commands
are being read from a file) the shell exits if a com-
mand fails.
-n commands are read, and variable substitution takes
place, but the commands are not executed.
-t shell exits after reading and executing one command.
-u treat unset variables as an error when substituting.
-v print input lines as they are read.
-x print the command line before it is executed.
- turn off -x and -v options
COMMANDS
Command consist of a sequence of words. The first word is
the command name and the tail is the arguments to the com-
mand. More than one command can be placed on a line, a ';'
separates the commands.
Conditional execution of commands can be formed be separat-
ing the command with the operators '&&' and '||', for 'and'
and 'or' resepctively. Logical 'and', if the execution of
the first command is successful the second one proceeds,
else the rest of the command line is terminated. Logical
'or', the second command is executed only if the first one
fails.
REPETITION AND CONDITIONAL EXECUTION OF COMMANDS
A number of inbuilt commands are provided for performing
loops and conditional execution. Loops
Three types of loop control are provided.
Printed 10/April/1987 1st April 1987 1
SH ST-UNIX User's Manual SH
for name [in word ...] do command-list done
For every iteration of the loop, name is setto the next
word in the word list. If the 'in' command and word
list are ommited the variable '$@' (see later) is used.
Execution of the command list terminates when ther are
no more words in the list.
This example displays the names of all files with the
extension '.c':
for i in *.c
do
echo File: $i
done
while command-list1 [ do command-list2 ] done
The while command executes command-list1 and if the
last command in the list returns true command-list2 is
executed. Execution continues until command-list1
fails.
The following example asks the user for a name of a
file to edit and then invokes the editor. When the edit
is complete the user is asked for another file name.
This continues indefinitly.
while true
do
echo -n File to edit
read filename
edit $filename
done
if command-list1 then list1 [ elif command-list2 then list2
] ... [ else list ] fi
If executes command-list1, if the last command in the
list returns true then list1 is executed. If the com-
mand fails control passes to elif, then, or if returns.
The example shows the printing of a filename is the
file exists.
Printed 10/April/1987 1st April 1987 2
SH ST-UNIX User's Manual SH
echo -n File /?
read filename
if test -f $filename
then
echo $filename
done
case word in [ pattern ) command-list ;; ] ... esac
The case command executes the command-list associated
withthe matching of word with pattern
The example shows how to change the name of a file.
echo -n File /?
read filename
case $filename in
a.c) filename=b.c;;
c.c) filename=b.c;;
esac
VARIABLES
The shell provides variables as in conventional languages.
Variables are assigned a value with the '=' operator. The
varaible name is composed of a sequence of letters, digits,
or characters * @ # ? $ !.
var-name=string
Variable substitution on the command line is performed using
the '$' operator.
$variable=a long string
$echo ${variable}
a long string
$
The '{' and '}' braces in the example may be ommited if spe-
cial characters are not contained in the variable name. The
special characters are discussed.
Printed 10/April/1987 1st April 1987 3
SH ST-UNIX User's Manual SH
${varname-word} If the variable is set (has been
assigned a value) it's value is substituted, else the
word is substituted.
${varname=word} If the variable is not set, it is set
to word, and it's value substituted.
${varname?word} If the variable is not set the word is
printed and the shell exits.
${varname+word} If the variable is set, word is substi-
tuted, otherwise nothing is substituted.
There are a number of internal parameters to the shell.
These can not be changed by assignment.
number The shell argument corresponding to number. For
example $0 is the command name 'sh'.
# The number of parameters to the shell.
- The options supplied to the shell.
? The value of the error returned by the last command
executed.
The shell has defined some variables which are accessable to
the user.
HOME The default directory used by 'cd' when no argu-
ment is supplied.
PATH The search path used in lokating a command to be
executed.
PS1 PS2 The prompt string, PS2 is used when a partialy
completed command is typed.
QUOTING OF STRINGS ON THE COMMAND
The interpretation of characters in the command line can be
changed by the use of quotes. The quotes ' and " are passed
unaltered to the command for it's interpretation. The '
quote passes everything unaltered, but the " quote inter-
prets $ as variable expansion. be not interpreted. This is
useful for inserting special characters, syuch as '$', into
the command line, and continueing very long lines (as the
newline character is ignored). A string in the backquotes ``
is executed as a command and the output of that command